package com.shujia;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HColumnDescriptor;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;

import java.io.IOException;

public class Demo1Test {
    public static void main(String[] args) throws IOException {
        // 创建配置，指定zk集群地址
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", "master,node1,node2");
        // 创建连接
        Connection conn = ConnectionFactory.createConnection(conf);

        // 创建Admin对象
        Admin admin = conn.getAdmin();

        // 创建 test_api 表
        HTableDescriptor test_api = new HTableDescriptor(TableName.valueOf("test_api"));

        // 创建cf1列簇
        HColumnDescriptor cf1 = new HColumnDescriptor("cf1");
        // 对列簇进行配置
        cf1.setTimeToLive(5); // 设置TTL
        cf1.setMaxVersions(3); // 设置版本
        // 增加列簇
        test_api.addFamily(cf1);


        admin.createTable(test_api);

        // 关闭连接
        conn.close();

    }
}
